#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int minimumOperations(string num) {
        int ans = 1e9;
        int len = num.size();

        for (int i = len - 1; i >= 0; i--) {
            if (num[i] == '0') {
                int pos = -1;
                for (int j = i - 1; j >= 0; j--) {
                    if (num[j] == '0' || num[j] == '5') {
                        pos = j;
                        break;
                    }
                }
                if (pos == -1) {
                    ans = len - 1;
                    break;
                }
                else {
                    ans = (len - 1 - i) + (i - pos - 1);
                    break;
                }
            }
        }
        int ans1 = 1e9;
        for (int i = len - 1; i >= 0; i--) {
            if (num[i] == '5') {
                int pos = -1;
                cout << "i==" << i << endl;
                for (int j = i - 1; j >= 0; j--) {
                    if (num[j] == '7' || num[j] == '2') {
                        pos = j;
                        //cout<<pos<<"jjj"<<endl;
                        break;
                    }
                }
                //  cout<<pos<<endl;
                if (pos == -1) {

                    break;
                }
                else {
                    // cout<<pos<<"==="<<endl;
                    ans1 = (len - 1 - i) + (i - pos - 1);
                    break;
                }
            }
        }
        //  cout<<ans<<" "<<ans1<<endl;
        if (ans == 1e9 && ans1 == 1e9)return len;
        return min(ans, ans1);


    }
    //  return 1;
};